/**
  ******************************************************************************
  * @file    can_driber.h
  * @author  Cresent
  * @version V1.0
  * @date    2019.4.15
  * @brief   CAN bus driver. 
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef CAN_DRIVER_H
#define CAN_DRIVER_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Exported macro ------------------------------------------------------------*/
#define CAN_TX_BUFFER_LEN 64
#define CAN_TX_SIZE 8

/* Private types -------------------------------------------------------------*/
typedef struct
{
	CAN_HandleTypeDef *hcan;         /* Pointer to a CAN_HandleTypeDef structure */
    CAN_TxHeaderTypeDef *pTxHeader;  /* Pointer to a CAN_TxHeaderTypeDef structure */
    CAN_RxHeaderTypeDef *pRxHeader;  /* Pointer to a CAN_RxHeaderTypeDef structure */
	unsigned char *pTxBuff;          /* Pointer to Tx Buffer */
	__IO unsigned short TxWrite;     /* Tx Buffer written location */
	__IO unsigned short TxRead;      /* Tx Buffer read location */
	__IO unsigned short TxCount;     /* Tx Buffer count */
}CAN_TX_FIFO_TypeDef;

/* Exported variables --------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/
HAL_StatusTypeDef CAN_FIFO_Init(CAN_TX_FIFO_TypeDef *hfifo, 
                                CAN_HandleTypeDef *hcan, 
                                CAN_TxHeaderTypeDef *TxHeader, 
                                CAN_RxHeaderTypeDef *RxHeader, 
								unsigned char *TxBuff,
                                unsigned int id);
HAL_StatusTypeDef CAN_SendData(CAN_TX_FIFO_TypeDef *hfifo,unsigned int id);
HAL_StatusTypeDef CAN_WriteToFIFO(CAN_TX_FIFO_TypeDef *hfifo, uint8_t *buff, uint16_t len);
HAL_StatusTypeDef CAN_ReceiveData(CAN_TX_FIFO_TypeDef *hfifo, uint8_t *data, unsigned int *id, unsigned int *len);

#endif /* CAN_DRIVER_H */
